//
//  UserCenterViewController.m
//  Edutohome
//
//  Created by xiaofeifei on 15/1/13.
//
//

#import "UserCenterViewController.h"
#import "ChangePwdViewController.h"
#import "OwnerCompleteViewController.h"
#import "ShipperCompleteViewController.h"
#import "LogisticsCompleteViewController.h"

@interface UserCenterViewController (){
    NSDictionary *_userDic;
}

@property (weak , nonatomic) IBOutlet UIButton *changeBtn;

@end

@implementation UserCenterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    if ([[GlobalData sharedGlobalData] userinfoDic] != nil) {
        UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 85, self.navView.frame.size.height-38, 80, 30)];
        [rightBtn setTitle:@"修改密码" forState:UIControlStateNormal];
        [rightBtn setBackgroundImage:[UIImage imageNamed:@"back_n.png"] forState:UIControlStateNormal];
        [rightBtn addTarget:self action:@selector(changePassword) forControlEvents:UIControlEventTouchUpInside];
        [self.navView addSubview:rightBtn];
    }
    [self getUserInfo];
    // Do any additional setup after loading the view from its nib.
}

- (void)getUserInfo{
    [SVProgressHUD showWithStatus:@"加载中" maskType:SVProgressHUDMaskTypeBlack];
    //传入的参数
    NSMutableDictionary *parameters = [GlobalData paramterDic];
    NSString *uid = [[GlobalData sharedGlobalData] userinfoDic][@"UserID"];
    [parameters addEntriesFromDictionary:@{@"userid":uid}];
    NSLog(@"%@",parameters);
    NSString *url = [NSString stringWithFormat:@"%@user/user",URL_ROOT];
    [[BaseNetwork alloc] initWithMethodUrl:url
                                    params:parameters
                               requestMode:DGHTTPMethodPOST
                               loadingShow:YES
                              didFinshLoad:^(id result) {
                                  [SVProgressHUD dismiss];
                                  id responseObject = result;
                                  [SVProgressHUD dismiss];
                                  NSLog(@"responseObject=%@",responseObject);
                                  _userDic = responseObject;
                                  [self configUI];
                                  
                              }];

}

- (void)configUI{
    NSDictionary *userDic = [[GlobalData sharedGlobalData] userinfoDic];
    _userNameLabel.text = [userDic[@"TrueName"] isEqual:[NSNull null]]?@"":userDic[@"TrueName"];
    _userStateLabel.text = [userDic[@"StateStr"] isEqual:[NSNull null]]?@"":userDic[@"StateStr"];
    _userVIPLabel.text = [NSString stringWithFormat:@"%@",[userDic[@"VipLevel"] isEqual:[NSNull null]]?@"":userDic[@"VipLevel"]];
    _userTypeLabel.text = [userDic[@"UserTypeStr"] isEqual:[NSNull null]]?@"":userDic[@"UserTypeStr"];
    _userCarNoLabel.text = [userDic[@"CarNo"] isEqual:[NSNull null]]?@"":userDic[@"CarNo"];
    _userTelLabel.text = [userDic[@"UserName"] isEqual:[NSNull null]]?@"":userDic[@"UserName"];
    _userAddressLabel.text = [userDic[@"Address"] isEqual:[NSNull null]]?@"":userDic[@"Address"];
    
//    _userCarTypeLabel.text = [NSString stringWithFormat:@"%@",[userDic[@"CarType"] isEqual:[NSNull null]]?@"":userDic[@"CarType"]];
//    _userCarSpecLabel.text = [NSString stringWithFormat:@"%@",[userDic[@"CarSpec"] isEqual:[NSNull null]]?@"":userDic[@"CarSpec"]];
}

- (void)changePassword{
    ChangePwdViewController *vc = [[ChangePwdViewController alloc] initWithNibName:nil bundle:nil];
    [self.navigationController pushViewController:vc animated:YES];
}


- (IBAction)gotoChangeUserInfo:(id)sender{
    int userType = [[[GlobalData sharedGlobalData] userinfoDic][@"UserType"] intValue];
    BasicViewController *vc = nil;
    if (userType == 0) {
        vc = [[OwnerCompleteViewController alloc] initWithNibName:nil bundle:nil];
    }
    else if (userType == 1) {
        vc = [[ShipperCompleteViewController alloc] initWithNibName:nil bundle:nil];
    }
    else if (userType == 2) {
        vc = [[LogisticsCompleteViewController alloc] initWithNibName:nil bundle:nil];
    }
    vc.navStr = @"修改个人资料";
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
